import 'package:after_sale_plugin/common/pdf_preview/controller.dart';

import 'package:after_sale_plugin/package_data_center.dart';
import 'package:after_sale_plugin/package_event.dart';
import 'package:after_sale_plugin/routes.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

import 'state.dart';

class ProductManualController extends LxBaseScrollOpacityController {
  // 状态
  ProductManualState state = ProductManualState();

  // 是 手册页面 / 指南页面
  bool isManual = true;

  // 是独轮车
  bool isScooter = true;

  @override
  onInit() async {
    super.onInit();

    isManual = PackageDataCenter.isProductManual;
    if (isManual) {
      getManualList();
    } else {
      getVideoGuideList();
    }
  }

  // 获取手册页面数据源
  getManualList({bool scooter = true}) {
    isScooter = scooter;
    state.productModels.clear();
    PackageEvent.getProductManual((p0) {
      List<dynamic> deviceMap = p0;
      List<ProductModel> productModels = deviceMap
          .map((e) => ProductModel.fromMap(e as Map<String, dynamic>))
          .toList();
      state.productModels.value = productModels;
    }, param: scooter ? 0 : 1);
  }

  // 产品手册 / 操作指南
  manual(ProductSubModel model) {
    Get.toNamed(
      Routes.pdfPreview,
      arguments: PdfPreviewArguments()
        ..navTitle = model.title
        ..pdfUrl = model.content,
    );
  }

  // 视频指南
  getVideoGuideList({bool scooter = true}) {
    isScooter = scooter;
    state.productModels.clear();
    PackageEvent.getVideoGuide((p0) {
      List<dynamic> deviceMap = p0;
      List<ProductModel> productModels = deviceMap
          .map((e) => ProductModel.fromMap(e as Map<String, dynamic>))
          .toList();
      state.productModels.value = productModels;
    }, param: scooter ? 0 : 1);
  }

  // 播放
  videoGuide(ProductSubModel model) {
    List<String> param = [model.title, model.content];
    PackageEvent.playVideo(null, param: param);
  }
}
